package com.detector.overflow;

import org.objectweb.asm.*;

/**
 * 类访问器 - 处理类级别的转换
 *
 * @author detector
 */
public class OverflowClassVisitor extends ClassVisitor {

    private static final String CONSTRUCTOR_NAME = "<init>";
    private static final String STATIC_INITIALIZER_NAME = "<clinit>";

    private final String className;
    
    public OverflowClassVisitor(int api, ClassVisitor cv, String className) {
        super(api, cv);
        this.className = className;
    }
    
    @Override
    public MethodVisitor visitMethod(int access, String name, String descriptor,
                                     String signature, String[] exceptions) {
        MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
        if (mv == null) {
            return null;
        }
        // 排除构造方法和静态初始化块
        if (CONSTRUCTOR_NAME.equals(name) || STATIC_INITIALIZER_NAME.equals(name)) {
            return mv;
        }

        return new OverflowMethodVisitor(api, mv, className, name, descriptor);
    }
}
